package com.core.model.lxf;

import com.core.model.AbstractEntity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * Created with IntelliJ IDEA.
 * User: lxf
 * Date: 2016/12/30
 * Time: 16:15
 * To change this template use Editor | File and Code Templates.
 */
@Entity
@Table(name = "account")
public class Account extends AbstractEntity {

    @Column
    private String account;
    @Column
    private String password;
    @Column
    private double balance;   //余额
    @Column(name = "freezed_amount")
    private double freezedAmount;  //冻结金额

    public Account() {
    }

    public Account(String account, double balance, double freezedAmount) {
        this.account = account;
        this.balance = balance;
        this.freezedAmount = freezedAmount;
    }

    public boolean transferTo(Account target, double amount) {
        if (this.isActive() && target.isActive()) {
            if ((this.balance - freezedAmount - amount) > 0) {
                this.balance = this.balance - amount;
                target.setBalance(target.getBalance() + amount);
                return true;
            } else {
                return false;
            }
        }
        return false;
    }


    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public double getFreezedAmount() {
        return freezedAmount;
    }

    public void setFreezedAmount(double freezedAmount) {
        this.freezedAmount = freezedAmount;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
